import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo2 {
        public static void main(String[] args) throws InterruptedException {
            // 依题意创建线程池
            ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, // 核心线程数
                    10, // 最大线程数
                    3, // 线程空闲时长
                    TimeUnit.SECONDS, // 线程空闲时长的时间单位
                    new LinkedBlockingQueue<>(100), // 任务队列
                    new ThreadPoolExecutor.DiscardPolicy()); // 拒绝策略为忽略最新任务

            // 测试执行
            for (int i = 0; i < 2000; i++) {
                new Thread(() -> {
                    System.out.println(Thread.currentThread().getName() + "已执行.");
                }, "thread-" + (i + 1)).start();
            }
        }
}
